<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
/**
 * SPA 认证功能：自定义用户登录功能。
 * Class LoginController
 * @package App\Http\Controllers\Api
 */
class LoginController extends Controller
{
    public function authenticate(Request $request)
    {
        $request->validate([
            'email' => 'required|string',
            'password' => 'required|string',
        ]);
        
        $credentials = $request->only('email', 'password');
        Log::info('LoginController authenticate');
        Log::info($credentials);

        if (Auth::attempt($credentials)) {
            // 通过认证..
            // return [
            //     'code' => 20000
            // ];
            return new Response('', 204);
        } else {
            return [
                'code' => 40000
            ];
        }
    }
}
